﻿using System.Collections.Generic;
using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    public class EffectivePackageNode_Base: IDGenerateNode
    {
        public override Color color => new Color(1f, 0.427f, 0.161f);
        
        [Input("last")] public SkillEditorActionNode self;
        [Output] public SkillEditorActionNode next;
        
        protected virtual ESkillEffectiveType actionType { get; }
        
        protected override void Process()
        {
            base.Process();

            if (this.self == null)
            {
                return;
            }
            
            var rAction = new SkillActionNode();
            rAction.actionType = (int)this.actionType;
            rAction.customConfig = this.CreateConfig();
            rAction.guid = this.GenerateID();

            this.self.setter?.Invoke(rAction);
            
            this.self.action = rAction;
            this.self.packageConfig?.actions.Add(rAction);
            this.self.prefabConfig?.prefab.actions.Add(rAction);

            var rSelfPackage = this.self.prefabConfig != null ? this.self.prefabConfig.prefab : this.self.packageConfig;
            this.next = new SkillEditorActionNode()
            {
                last = this.self,
                packageConfig = rSelfPackage
            };
            this.self.next = this.next;
        }

        protected virtual SkillActionNode CreateAction()
        {
            var rAction = new SkillActionNode();
            return rAction;
        }

        protected virtual SkillCustomConfig CreateConfig()
        {
            return null;
        }
    }

}